package com.itheima.thread.threadPool.future;

import java.util.concurrent.*;

/**
 * @Author: Ethan Yankang
 * @Program: Interview
 * @Date: 2024-08-15 21:15
 **/
public class FutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
//        获取线程池对象
        ExecutorService es = Executors.newCachedThreadPool();
//        创建callable类型的任务对象
        Future<Integer> future= (Future<Integer>) es.submit(new MyCall(1,1));
//        判断线程任务是否完成
        boolean done = future.isDone();
        System.out.println("done = " + done);
        boolean  toCancel = future.cancel(false);
        System.out.println("toCancel(取消任务执行的结果) = " + toCancel);
        Integer i = future.get(10, TimeUnit.SECONDS);
        System.out.println("i(任务执行的结果是) = " + i);
    }
}
